home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 422_02 / dosutil / type4.c < prev    next >
C/C++ Source or Header  |  1994-03-20  |  1KB  |  53 lines

  1. /*
  2.  * Program to display a file assuming tab stops are at 4 character
  3.  * Intervals. By redirecting the output from this program to the
  4.  * printer, you may properly print the MICRO-C listings.
  5.  *
  6.  * In MICRO-C, the operation "a && b" is defined as returning zero
  7.  * without evaluating "b" if "a" evaluates to zero, otherwise "b"
  8.  * is evaluated and returned.
  9.  *
  10.  * The statement "j = (chr != '\n') && j+1" shows how && (or ||) may
  11.  * be used to create a very efficent conditional expression in MICRO-C.
  12.  * NOTE that this is not "standard", and is NOT PORTABLE. The more
  13.  * conventional equivalent is: "j = (chr != '\n') ? j+1 : 0"
  14.  *
  15.  * Copyright 1989-1994 Dave Dunfield
  16.  * All rights reserved.
  17.  *
  18.  * Permission granted for personal (non-commercial) use only.
  19.  *
  20.  * Compile command: cc type4 -fop
  21.  */
  22. #include <stdio.h>
  23.  
  24. #define TAB_SIZE    4        /* tab spacing */
  25.  
  26. main(argc, argv)
  27.     int argc;
  28.     char *argv[];
  29. {
  30.     int i, j, chr;
  31.     FILE *fp;
  32.  
  33.     if(argc < 2)
  34.         abort("\nUse: type4 <filename*>\n");
  35.  
  36. /* Set output to buffered for higher speed */
  37.     stdout = setbuf(stdout, 512);
  38.  
  39.     for(i=1; i < argc; ++i) {
  40.         if(fp = fopen(argv[i], "rv")) {
  41.             j = 0;
  42.             while((chr = getc(fp)) != EOF) {
  43.                 if(chr == '\t') {            /* tab */
  44.                     do
  45.                         putc(' ', stdout);
  46.                     while(++j % TAB_SIZE); }
  47.                 else {                        /* not a tab */
  48.                     j = (chr != '\n') && j+1;    /* see opening comment */
  49.                     putc(chr, stdout); } }
  50.             fclose(fp); } }
  51.     fflush(stdout);
  52. }
  53.